//  
//   JKMusicTool.m
//   QQMusic
//  
//   Created by albert on 16/4/7.
//   Copyright (c) 2016年 albert. All rights reserved.
//  

#import "JKMusicTool.h"
#import "JKMusicModel.h"
#import "MJExtension.h"
#import "JKAudioTool.h"

@implementation JKMusicTool

static NSArray *_musics;
static JKMusicModel *_playingMusic;

+ (void)initialize{
    if (_musics == nil) {
        _musics = [JKMusicModel objectArrayWithFilename:@"Musics.plist"];
    }
    
    if (_playingMusic == nil) {
        _playingMusic = _musics[4];
    }
}

/** 所有的音乐 */
+ (NSArray *)musics{
    return _musics;
}

/** 正在播放的音乐 */
+ (JKMusicModel *)playingMusic{
    return _playingMusic;
}

/** 设置要播放的音乐 */
+ (void)setplayingMusic:(JKMusicModel *)playingMuisic{
    //  设置要播放的音乐
    [JKAudioTool stopMusicWithMusicName:_playingMusic.filename];
    _playingMusic = playingMuisic;
}

/** 获取下一首 */
+ (JKMusicModel *)nextMusic{
    //  1、拿到当前播放歌词下标
    NSInteger currentIndex = [_musics indexOfObject:_playingMusic];
    
    //  2、取出下一首
    NSInteger nextIndex = ++currentIndex;
    if (nextIndex >= _musics.count) {
        nextIndex = 0;
    }
    return _musics[nextIndex];
}

/** 获取上一首 */
+ (JKMusicModel *)previousMusic{
    //  1、拿到当前播放歌词下标
    NSInteger currentIndex = [_musics indexOfObject:_playingMusic];
    
    //  2、取出上一首
    NSInteger previousIndex = --currentIndex;
    if (previousIndex < 0) {
        previousIndex = _musics.count - 1;
    }
    return _musics[previousIndex];
}
@end
